#ifndef _XDMA_IOCALLS_POSIX_H_
#define _XDMA_IOCALLS_POSIX_H_

#ifndef _WINDOWS
// TODO: Windows build support
#include <linux/ioctl.h>
#endif

/* Use 'x' as magic number */
#define XDMA_IOC_MAGIC	'x'
/* XL OpenCL X->58(ASCII), L->6C(ASCII), O->0 C->C L->6C(ASCII); */
#define XDMA_XCL_MAGIC 0X586C0C6C

#define IOCTL_XDMA_PERF_V1 (1)
#define XDMA_ADDRMODE_MEMORY (0)
#define XDMA_ADDRMODE_FIXED (1)

/*
 * S means "Set" through a ptr,
 * T means "Tell" directly with the argument value
 * G means "Get": reply by setting through a pointer
 * Q means "Query": response is on the return value
 * X means "eXchange": switch G and S atomically
 * H means "sHift": switch T and Q atomically
 *
 * _IO(type,nr)		    no arguments
 * _IOR(type,nr,datatype)   read data from driver
 * _IOW(type,nr.datatype)   write data to driver
 * _IORW(type,nr,datatype)  read/write data
 *
 * _IOC_DIR(nr)		    returns direction
 * _IOC_TYPE(nr)	    returns magic
 * _IOC_NR(nr)		    returns number
 * _IOC_SIZE(nr)	    returns size
 */

#define KM_DATA_BYTES	(1024 + 256)
#define KM_DATA_WORDS	KM_DATA_BYTES/4

struct xdma_ioc_info {
        unsigned short       vendor;
        unsigned short       device;
        unsigned short       subsystem_vendor;
        unsigned short       subsystem_device;
        unsigned             dma_engine_version;
        unsigned             driver_version;
        unsigned long long   feature_id;
        unsigned             ocl_frequency;
};

typedef struct Write_Usr_ioctl_ctx {
	unsigned int addr;
	unsigned int data;
} Write_Usr_ioctl_ctx;

typedef struct decd_ioctl_ctx {
	void *pDataBuf;
	unsigned long inLen;
	unsigned long outLen;
} decd_ioctl_ctx;

// typedef struct sm1_ioctl_ctx {
// 	void *inbuf;
// 	void *outbuf;
// 	unsigned int length;
// 	unsigned int ssx_cmd;
// } sm1_ioctl_ctx;

typedef struct sm1_ioctl_ctx {
	void *inbuf;
	void *outbuf;
	unsigned int inputLength;
	unsigned int outputLength;
	unsigned int ssx_cmd;
} sm1_ioctl_ctx;

typedef struct fhe_ioctl_ctx {
	unsigned int decdata;
	unsigned char encdata[128];
} fhe_ioctl_ctx;


enum enc_mode {
	DEC_MODE = 0,
	ENC_MODE = 1
};


enum error_code {
	RESTART = -108,
};



#define IOCTL_RESET						_IO('q', 1)
#define IOCTL_WRITE_USR					_IOWR('q', 2, struct Write_Usr_ioctl_ctx *)
#define IOCTL_GETCARDNUM				_IOWR('q', 3, unsigned char *)
#define IOCTL_FHE_GENKEY				_IO('q', 4)
#define IOCTL_FHE_ENC					_IOWR('q', 5, struct fhe_ioctl_ctx *)
#define IOCTL_FHE_DEC					_IOWR('q', 6, struct fhe_ioctl_ctx *)
#define IOCTL_NFHE_EXPORT_PUBKEY		_IOR('q', 7, unsigned char *)
#define IOCTL_NFHE_IMPORT_PUBKEY		_IOW('q', 8, unsigned char *)
#define IOCTL_NFHE_DMA_SM1				_IOWR('q', 9, struct sm1_ioctl_ctx *)
#define IOCTL_DECD						_IOWR('q', 10, struct decd_ioctl_ctx *)
#define IOCTL_NFHE_TEST					_IOWR('q', 11, struct decd_ioctl_ctx *)


#endif /* _XDMA_IOCALLS_POSIX_H_ */

